import request from './request'

export const venueApi = {
  // 获取场地列表
  getVenueList(params) {
    // 转换参数名称：page_size -> pageSize
    const backendParams = {
      page: params.page,
      pageSize: params.page_size || params.pageSize
    }
    
    return request({
      url: '/venue/list',
      method: 'get',
      params: backendParams
    })
  },

  // 获取场地详情
  getVenueDetail(id) {
    return request({
      url: `/venue/${id}`,
      method: 'get'
    })
  },

  // 创建场地
  createVenue(data) {
    return request({
      url: '/venue/create',
      method: 'post',
      data
    })
  },

  // 更新场地
  updateVenue(id, data) {
    return request({
      url: `/venue/${id}`,
      method: 'put',
      data
    })
  },

  // 更新场地状态
  updateVenueStatus(id, status) {
    return request({
      url: `/venue/${id}/status`,
      method: 'post',
      params: { status }
    })
  },

  // 检查场地可用性
  checkAvailability(id, startTime, endTime) {
    return request({
      url: `/venue/${id}/availability`,
      method: 'get',
      params: { startTime, endTime }
    })
  },

  // 预订场地
  bookVenue(id, eventId, startTime, endTime) {
    return request({
      url: `/venue/${id}/book`,
      method: 'post',
      params: { eventId, startTime, endTime }
    })
  },

  // 取消场地预订
  cancelBooking(id, eventId) {
    return request({
      url: `/venue/${id}/cancel-booking`,
      method: 'post',
      params: { eventId }
    })
  },

  // 搜索场地
  searchVenues(params) {
    return request({
      url: '/venue/search',
      method: 'get',
      params
    })
  },

  // 获取我管理的场地
  getMyVenues() {
    return request({
      url: '/venue/my-venues',
      method: 'get'
    })
  },

  // 获取场地预订记录
  getVenueBookings(id, params) {
    return request({
      url: `/venue/${id}/bookings`,
      method: 'get',
      params
    })
  },

  // 删除场地
  deleteVenue(id) {
    return request({
      url: `/venue/${id}`,
      method: 'delete'
    })
  }
}

